package com.axter.libs.photo.choosephoto;

import android.util.Log;
import android.view.View;

import com.axter.libs.base.adapter.CommonAdapter;
import com.axter.libs.base.adapter.IBaseViewHolder;
import com.axter.libs.base.adapter.ICheckedInterface;
import com.axter.libs.photo.bean.MediaInfo;

public class ChoosePhotoAdapter extends CommonAdapter<MediaInfo> {
    public ChoosePhotoAdapter(boolean isSingle, ICheckedInterface selectedInterface) {
        setCheckedMode(isSingle);
        setCheckedInterface(selectedInterface);
    }

    @Override
    public int getViewTypeCount() {
        return 5;
    }

    @Override
    public int getItemViewType(int position) {
        return getItem(position).getType() == MediaInfo.TYPE_IMAGE && getItem(position).isGif() ? MediaInfo.TYPE_GIF : getItem(position).getType();
    }

    @Override
    public IBaseViewHolder<MediaInfo> createViewHolder(int itemType) {
        switch (itemType) {
            case MediaInfo.TYPE_IMAGE:
                return new ChoosePhotoViewHolderImage(this);
            case MediaInfo.TYPE_CAMERA:
                return new ChoosePhotoViewHolderCamera();
            case MediaInfo.TYPE_GIF:
                return new ChoosePhotoViewHolderGif(this);
            case MediaInfo.TYPE_VIDEO:
                return new ChoosePhotoViewHolderVideo(this);
            default:
                return new ChoosePhotoViewHolderImage(this);
        }
    }

    protected View.OnClickListener checklistener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            int position = (int) v.getTag();
            setCheckedItem(position);
            // TODO 可能是gridview中的bug，getView混乱
            notifyDataSetChanged();
        }
    };
}
